﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CharSetExtensions.cs" company="Marcin Jastrzebski">
//   Copyright (c) Marcin Jastrzebski (marcin@marcinj.net)
// </copyright>
// <summary>
//   The char set extensions.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace mPassRT.ViewModels.PasswordGenerator
{
    using System;

    using KeePassLib.Cryptography.PasswordGenerator;

    /// <summary>The char set extensions.</summary>
    public static class CharSetExtensions
    {
        #region Public Methods and Operators

        /// <summary>Sets or clears the flag.</summary>
        /// <param name="current">The current value.</param>
        /// <param name="flags">The flags to set or clear.</param>
        /// <param name="value">True to set and false to clear.</param>
        /// <returns>The result of the operation.</returns>
        public static CharSet Set(this CharSet current, CharSet flags, bool value)
        {
            if (value)
            {
                return current | flags;
            }

            return current & (~flags);
        }

        /// <summary>Converts the charset value to a string containing the corresponding characters.</summary>
        /// <param name="charSet">The char set.</param>
        /// <returns>The <see cref="string"/>.</returns>
        public static string ToCharSetString(this CharSet charSet)
        {
            switch (charSet)
            {
                case CharSet.UppercaseLetters:
                    return PwCharSet.UpperCase;

                case CharSet.LowercaseLetters:
                    return PwCharSet.LowerCase;

                case CharSet.Digits:
                    return PwCharSet.Digits;
                case CharSet.Minus:
                    return "-";

                case CharSet.Space:
                    return " ";

                case CharSet.Underscore:
                    return "_";

                case CharSet.SpecialCharacters:
                    return PwCharSet.PrintableAsciiSpecial;

                case CharSet.Brackets:
                    return PwCharSet.Brackets;

                case CharSet.HighAnsi:
                    return new PwCharSet().HighAnsiChars;

                default:
                    throw new ArgumentException("Unexpected or multiple enumeration values.", "charSet");
            }
        }

        #endregion
    }
}